#include "StdAfx.h"
#include "resource.h"
#include "TPMediaDlg.h"
#include <atlmisc.h>
#include "TPPlayer.h"
#include "TPFile.h"


LRESULT CTPMediaDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
	//////////////////////////////////////////////////////////////////////////
	DoDataExchange(FALSE);

	//////////////////////////////////////////////////////////////////////////
	AtlCreateMenuBar(m_hWnd, ATL_IDM_MENU_DONECANCEL);

	//////////////////////////////////////////////////////////////////////////
	DWORD dwStyleEx = m_wndList.GetExtendedListViewStyle();
	dwStyleEx |= LVS_EX_FULLROWSELECT;
	m_wndList.SetExtendedListViewStyle(dwStyleEx);

	CString strText;
	strText.LoadString(IDS_ORDER);
	m_wndList.AddColumn(_T("No."), 0);
	strText.LoadString(IDS_FILE);
	m_wndList.AddColumn(strText, 1);
	m_wndList.SetColumnWidth(1, LVSCW_AUTOSIZE_USEHEADER);

	const int		iCount	= CTPPlayer::GetTPFileCount();
	const CTPFile*	pFile	= NULL;
	CString			strIndex;

	for ( int i = 0; i < iCount; ++i )
	{
		pFile = CTPPlayer::GetTPFile(i);

		strIndex.Format(_T("%d"), i + 1);

		m_wndList.InsertItem(i, strIndex);
		m_wndList.AddItem(i, 1, pFile->GetTitle());
	}

	return bHandled = FALSE;
}

LRESULT CTPMediaDlg::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	// TODO: Add your message handler code here and/or call default
	if ( ::IsWindow(m_wndList) )
	{
		CRect rcClient;
		GetClientRect(rcClient);

		CRect rcList(rcClient.left + 5, rcClient.top + 5, rcClient.right - 5, rcClient.bottom - 5);

		m_wndList.MoveWindow(rcList);
		m_wndList.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER);
	}

	return 0;
}

LRESULT CTPMediaDlg::OnMenuOK(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& bHandled)
{
	m_iIndex = m_wndList.GetSelectedIndex();

	bHandled = FALSE;

	return 0;
}

int CTPMediaDlg::GetSelectIndex() const
{
	return m_iIndex;
}
